import ExportJsonExcel from 'js-export-excel';
export const dcData = (dataSource: any, columns: any, title: string) => {
  const option: any = {};
  option.fileName = title;
  option.datas = [
    {
      sheetData: dataSource.map((item: any) => {
        const result: any = {};
        columns.forEach((c: any) => {
          result[c.dataIndex] = item[c.dataIndex];
        });
        return result;
      }),
      sheetName: '表格', // Excel文件名称
      sheetFilter: columns.map((item: any) => item.dataIndex),
      sheetHeader: columns.map((item: any) => item.title),
      columnWidths: columns.map(() => 10),
    },
  ];

  const toExcel = new ExportJsonExcel(option);
  toExcel.saveExcel();
};
